package com.hyx.spring.config;

import com.hyx.spring.bean.Person;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

/**
 * @Author hyx
 * @Description SPRING配置类，具体：通过在类上加上@Configuration注解，并在方法上加上@Bean注解，
 * 就能够将方法中创建的JavaBean注入到Spring的IOC容器中
 * ①扫描排除注解标注的类我们现在排除@Controller、@Service和注解，我们可以在PersonConfig类上通过
 * @ComponentScan注解的excludeFilters()实现
 * ②扫描只包含注解标注的类 ——使用includeFilters()来指定只包含哪些注解标注的类时，需要禁用默认的过滤规则。
 * ③重复注解——在Java8中表示@ComponentScan注解是一个重复注解，如果使用的是Java8之前的版本，
 * 我们就不能直接在类上写多个@ComponentScan注解
 * @Date 2024/3/10 11:16
 * @Version 1.0
 */
@Configuration
//@ComponentScan(value = "com.hyx.spring",excludeFilters =
//        {@ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Controller.class, Service.class})})
//@ComponentScan(value = "com.hyx.spring", includeFilters = {
//        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class})
//        }, useDefaultFilters = false)
//@ComponentScan(value = "com.hyx.spring", includeFilters = {
//        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Service.class})
//}, useDefaultFilters = false)
@ComponentScan(value = "com.hyx.spring", includeFilters = {
        @ComponentScan.Filter(type = FilterType.CUSTOM, classes = {MyTypeFilter.class})
}, useDefaultFilters = false)
public class PersonConfig {

    @Bean("person") //明确指定标注方法的名称
    public Person person1(){
        return new Person("binghe01",19,null);
    }
}
